let https = require('https');
let httpPort = 443;
let httpPath = '/rest/com/vmware/cis/session';
let httpMethod = 'POST';

// Prepare the HTTP request.
my_http_options = {
    host: "192.168.1.80",
    port: httpPort,
    path: httpPath,
    method: httpMethod,
    rejectUnauthorized: false,
    requestCert: true,
    agent: false,
    auth: "administrator@vsphere.local" + ":" + "0okm9ijn)OKM(IJN"
};

// Define the callbacks.
function callback(res) {
    console.log("STATUS: " + res.statusCode);
    res.on('error', function (err) {
        console.log("ERROR in SSO authentication: ", err)
    });
    res.on('data', function (chunk) {
    });
    res.on('end', function () {
        if (res.statusCode === 200) {
            // Save session ID authentication.
            let cookieValue = res.headers['set-cookie'];
            my_http_options.headers = {'Cookie': cookieValue};
            // Remove username-password authentication.
            my_http_options.auth = {};
        }
        console.log("Session ID:\n" + res.headers['set-cookie']);
    });

// Issue the session creation request.
}
https.request(my_http_options, callback).end();
